import { randomId } from './tool'
import { Button, AnyButton, EditItem } from '@/form'

// 类型集合
export const createMap = {
  input: '输入框',
  select: '下拉框',
  range: '时间选择器'
}

/********************* create Button Start ************************/

type createProps = 'id' | 'withModal' | 'withDropdown' | 'isEdit' | 'isPreset' | 'type'

const createBtnCommon = (): Pick<Button, createProps> => ({
  id: randomId(),
  type: 'primary',
  withModal: false,
  withDropdown: false,
  isEdit: false,
  isPreset: true
})

export const createBtnUtils = {
  createAdd: (): Button<true> => ({
    ...createBtnCommon(),
    withModal: true,
    modal: {
      title: '新增',
      confirm: true,
      isForm: true,
      modalInfo: []
    },
    label: '新增'
  }),
  createDelete: (): Button => ({
    ...createBtnCommon(),
    label: '删除',
    danger: true
  }),
  createExport: (): Button => ({
    ...createBtnCommon(),
    label: '导出',
    ghost: true
  }),
  createImport: (): Button<true> => ({
    ...createBtnCommon(),
    label: '批导',
    withModal: true,
    modal: {
      title: '批导',
      confirm: true,
      isForm: true,
      modalInfo: []
    },
    ghost: true
  }),
  createDiy: (): AnyButton => ({
    ...createBtnCommon(),
    isPreset: false,
    label: '自定义',
    ghost: true,
    modal: {
      title: '自定义',
      confirm: true,
      isForm: true,
      modalInfo: []
    },
    popoverVisible: false,
    dropdownVisible: false,
    dropdownList: []
  })
}

/********************* create Button End ************************/

/********************* create FormItem Start ************************/

export const createFormItemUtils = {
  createInput: (): EditItem.Input => ({
    id: randomId(),
    type: 'input',
    label: `label`,
    placeholder: '请输入字段名称prop',
    prop: '',
    span: 5.5
  }),
  createSelect: (): EditItem.Select => ({
    id: randomId(),
    type: 'select',
    label: `label`,
    prop: void 0,
    placeholder: '请设置',
    dictType: 'dict',
    dictName: '',
    dicts: [] as DictItem[],
    selectDict: void 0,
    open: true,
    innerOpen: false,
    span: 5.5
  }),
  createRange: (): EditItem.Range => ({
    id: randomId(),
    type: 'range',
    label: `查询时间`,
    prop: '',
    placeholder: ['开始时间', '结束时间'],
    span: 7.5
  })
}

/********************* create FormItem End ************************/
